package com.imodia.checkoo.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.hsq.commons.util.db.GenericIbatisDao;
import com.hsq.commons.util.db.SqlParam;
import com.hsq.commons.util.db.annotation.SqlSpace;
import com.imodia.checkoo.bean.CmsModelBean;
import com.imodia.checkoo.service.CmsModelService;

@SqlSpace(spaceName = "cmsmodel")
@Service
public class CmsModelServiceImpl extends
		GenericIbatisDao<CmsModelBean, Integer> implements CmsModelService {

	public int updateDefault(CmsModelBean obj) {
		String sql = "update cms_model set is_default =0 where ref_id = "
				+ obj.getRefId() + " and ref_rs_id = " + obj.getRefRsId()
				+ " and id <>" + obj.getId();
		return this.getSqlDao().update(sql);
	}
	
	public List<CmsModelBean> list(int refRsId,int refId){
		SqlParam sqlModel = new SqlParam();
		sqlModel.andEqualTo("ref_id", String.valueOf(refId));
		sqlModel.andEqualTo("ref_rs_id",  String.valueOf(refRsId));
		return super.list(sqlModel);
	}
	
	
	public void delete(int refRsId,int refId){
		this.getSqlDao().delete("delete from cms_model where ref_rs_id = "+refRsId+" and ref_id = "+refId);
	}
	
}